<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('洁净煤发放信息')" />
</head>
<body class="gray-bg">
<div class="container-div">

    <div class="row">
        <div class="col-sm-12 search-collapse">

            <div class="row">
                <div class="col-sm-12">
                    <h3>[[${village.deptName}]]洁净煤发放信息录入</h3>
                </div>
            </div>
            <form id="formId">
                <div class="select-list">
                    <p>
                        <label>录入数据：</label>
                        <input type="hidden" name="villageId" th:value="${village.deptId}">
                        <a class="btn btn-success btn-sm" onclick="$.table.exportExcel()">下载表格</a>
<!--                        <a class="btn btn-success btn-sm" href="/洁净煤发放信息录入.xls" download>下载表格</a>-->
<!--                        <button th:text="上传表格" type="button" id="contentFileUpload" class="btn btn-success btn-sm"/>-->
                        <input type="hidden" name="contentFile" id="contentFile"/>
                        <a class="btn btn-warning btn-sm"  onclick="$.operate.add()">信息录入</a>
                    </p>
                    <ul>
                        <li>
                            <label>查找：</label>
                            <input type="text" name="keyword"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('jjm:clientUserorder:edit')}]];
    var removeFlag = [[${@permission.hasPermi('jjm:clientUserorder:remove')}]];
    var prefix = ctx + "jjm/clientUserorder";
    layui.use('upload', function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#contentFileUpload' //绑定元素
            ,url: prefix + '/importData?villageId='+[[${village.deptId}]] //上传接口
            ,multiple: true
            ,accept: 'file'
            ,before: function () {
                $.modal.loading("正在上传数据，请稍后...");
            }
            ,done: function(result){
                //上传完毕回调
                $.modal.closeLoading();
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess(result.msg);
                    $.table.refresh();
                } else{
                    $.modal.enable();
                    $.modal.alertWarning(result.msg)
                }
            }
            ,error: function(err){
                $.modal.closeLoading();
                $.modal.alertError("上传失败");
            }
        });
    });
    $(function() {
        var options = {
            url: prefix + "/listTable?status=1&villageId="+[[${village.deptId}]],
            updateUrl: prefix + "/edit/{id}?type=2",
            createUrl: prefix + "/addDeliver/{id}?type=2&villageId="+[[${village.deptId}]],
            exportUrl: prefix + "/export?status=1&villageId="+[[${village.deptId}]],
            importUrl: prefix + "/importData?villageId="+[[${village.deptId}]],
            confirmUrl: prefix + "/confirm",
            modalName: "居民购煤信息",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            columns: [
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    title: "编号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'masterName',
                    title: '户主姓名'
                },
                {
                    field: 'masterPhoneNumber',
                    title: '手机号'
                },
                {
                    field: 'masterIdentityCardNumber',
                    title: '身份证号'
                },
                {
                    field: 'amount',
                    title: '购煤数量（吨）'
                },
                {
                    field: 'money',
                    title: '购煤款'
                },
                {
                    field: 'createTime',
                    title: '购煤时间'
                },
                {
                    field: 'receiveAmount',
                    title: '收煤数量（吨）'
                },
                {
                    field: 'takeinTime',
                    title: '收煤时间'
                },
                {
                    field: 'receiver',
                    title: '收煤人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status){
                            //已发货，确认收煤
                            if(row.status == 1){
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="confirm(\'' + row.id + '\')">确认收煤</a> ');
                            }else if(row.status == 2 && row.takeinTime){
                                actions.push('<span class="btn btn-default btn-xs">'+new Date(row.takeinTime).format("yyyy-MM-dd")+"收到煤</span>&nbsp;");
                            }
                        }
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function purchase() {
        var amount = [[${sumOrder?.amount}]];
        if(amount && amount > 0){
            $.modal.openTab("集中购煤",prefix+"/purchase");
        }else{
            $.modal.alertWarning("本批次暂未购煤");
        }
    }
    function purchaseRecord() {
        $.modal.openTab("购煤记录","/jjm/order?villageId="+$("#villageId").val());
    }

    function confirm(id) {
        table.set();
        $.modal.confirm("您确认该居民已收到煤吗？", function() {
            var url = $.common.isEmpty(id) ? table.options.confirmUrl : table.options.confirmUrl.replace("{id}", id);
            var data = { "id": id };
            $.operate.submit(url, "post", "json", data);
        });

    }
</script>
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <span color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </span>
        </div>
    </form>
</script>
</body>
</html>